// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    @property(cc.Label)
    note: cc.Label = null;

    value = 0;
    cost = 0;
    start () {
        this.nodes.ani.children.forEach((val, idx) => {
            this.touchEndEventScale(val, () => {
                this.value = idx + 1;
                this.cost = this.value * 10000;
                this.note.string = `当前想要的为${this.value}点智商, 花费${ccs.gf.getOmitNum(this.cost)}元`;
            })
        })
        this.touchEndEventScale(this.nodes.ensure, () => {
            if(this.value <= 0) return;
            if(game.playerMgr.heroInfo.iq < this.value) {
                this.note.string = `智商不足`;
                game.recordMgr.addList({name: "你", action: `想参加智力博弈，智商不足`});
                return
            }
            if(!game.playerMgr.calMoney( -this.cost)) {
                this.note.string = `金钱不足`;
                game.recordMgr.addList({name: "你", action: `想参加智力博弈，金钱不足`});
                return
            }
            game.playerMgr.changeEffect({iq: this.value}, -1);
            this._close();
            game.recordMgr.addList({name: "你", action: `参与了智力博弈，花费${this.value}点智力`, effect: `IQ - ${this.value}，金钱 - ${this.cost}`});
            ccs.winMgr.showWin("popPlaySuduWin", { diffcult: this.value });
        })
    }

}
